package org.example.mall.admin.model.entity.manage;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.example.mall.admin.configuration.file.Url;
import org.example.mall.admin.constant.vaild.C;
import org.example.mall.admin.constant.vaild.Q;
import org.example.mall.admin.constant.vaild.U;
import org.example.mall.admin.model.enums.manage.TreeTypeEnum;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 系统分类树
 * </p>
 *
 * @author hzq
 * @since 2022-01-08
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_tree")
@ApiModel(value = "SysTree对象", description = "系统分类树")
public class SysTree extends Model<SysTree> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "树id")
    @TableId(value = "tree_id", type = IdType.AUTO)
    @NotNull(message = "treeId不能为空", groups = U.class)
    private Integer treeId;

    @NotBlank(message = "名称不能为空", groups = C.class)
    @ApiModelProperty(value = "树名称")
    @TableField("name")
    private String name;

    @ApiModelProperty(value = "父级id")
    @TableField("parent_id")
    private Integer parentId;

    /**
     * @see TreeTypeEnum
     */
    @ApiModelProperty(value = "树类型")
    @TableField("tree_type")
    @NotNull(message = "类型不能为空", groups = {C.class, Q.class})
    private Integer treeType;

    @ApiModelProperty(value = "排序")
    @TableField("sort")
    private Integer sort;

    @ApiModelProperty(value = "创建时间")
    @TableField("create_time")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField("update_time")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "版本")
    @TableField("version")
    @Version
    private Integer version;

    @ApiModelProperty(value = "层级")
    @TableField("hierarchy")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private Integer hierarchy;

    @Url
    @ApiModelProperty(value = "扩展字段")
    @TableField("extra")
    private String extra;

    @ApiModelProperty(value = "扩展字段")
    @TableField("expand")
    private String expand;

    @ApiModelProperty(value = "扩展字段")
    @TableField("develop")
    private String develop;

    @Override
    protected Serializable pkVal() {
        return this.treeId;
    }

}
